package com.example.demowebview;

import java.util.ArrayList;

import com.example.adapter.BookAdapter;
import com.example.base.Book;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class ListBookActivity extends Activity implements OnItemClickListener, OnItemLongClickListener{
	public static final String LINK = "LINK";
	private ListView listview;
	private BookAdapter adapter;
	private ArrayList<Book> listData = new ArrayList<Book>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_book);
		listview = (ListView) findViewById(R.id.listview);
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 1", "http://news.zing.vn/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 2", "http://vnexpress.net/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 3", "http://kenh14.vn/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 4", "http://dantri.com.vn/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 5", "http://genk.vn/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 6", "https://www.youtube.com/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 7", "https://www.tinhte.vn/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 8", "http://yeunguoiviet.com/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 9", "http://tuoitre.vn/"));
		listData.add(new Book(R.drawable.ic_launcher, "Truyện 10", "http://mong.vn/truyen"));
		adapter = new BookAdapter(ListBookActivity.this, R.layout.item_book, listData);
		listview.setAdapter(adapter);
		listview.setOnItemClickListener(this);
		listview.setOnItemLongClickListener(this);
	}

	private void ShowMessage(String string){
		Toast.makeText(ListBookActivity.this, string, Toast.LENGTH_LONG).show();
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
		Intent intent = new Intent(ListBookActivity.this, MainActivity.class);
		intent.putExtra(LINK, listData.get(position).link);
		startActivity(intent);
	}

	@Override
	public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
		ShowMessage("Ban da chon vi tri " + (position +1));
		return false;
	}
	
}
